package com.da.javatest.niuke.baodian;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2020/10/17 22:45
 * https://www.nowcoder.com/practice/a0c19f3489774fe693d71490ce83b648?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C75NextElement {
    public static int[] findNext(int[] A, int n) {
        int[] data = new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = -1;
            int max = Integer.MAX_VALUE;
            for (int j = i + 1; j < n; j++) {
                if (max == 1) {
                    break;
                }
                int temp = A[j] - A[i];
                if (temp > 0 && temp < max) {
                    data[i] = A[j];
                    max = temp;
                }
            }
        }
        return data;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(findNext(new int[] {11, 13, 10, 5, 12, 21, 3}, 7)));
    }
}